*******************************************************************************************************
* README.txt
* Guide to replication files for Gibson & Shrader, "Time use and productivity: the returns to sleep"
*******************************************************************************************************



**************************
* Data & folder structure
**************************
* File size limits prevent us from putting the entire package into a single .tar archive with the required directory structure. The recommended structure is outlined here.

* Beneath the working directory, the following subdirectories are required:
code - Scripts should execute from anywhere, but placing them in this folder is recommended.
data - See below for detail on subdirectories.
graphs - Initially empty. Scripts will populate.
logs - Initially empty. Scripts will populate.
tables - Initially empty. Scripts will populate. Beneath /tables a directory called /xsec is required.

* Beneath the /data directory, the following subdirectories are required. Extracting all .tar files in the /data directory will create the necessary structure. One .tar archive is provided for each subdirectory, except in cases where a subdirectory is initially empty. The file "other-data.tar.gz" contains a few smaller files and required empty subdirectories. 
atus - American Time Use Survey data.
bea reis - BEA Regional Economic Information System
census - Census demographic data.
counties db - Census Counties Database
county_tz - County-level time zone data.
CPS - Current Population Survey data from BLS. Some variables pertaining to ATUS respondents are available only in their CPS files.
demographics - Additional demographic data.
gis - Maps used to compute geographic centroids. These centroids are inputs to the sunset time calculation, and are used to compute distance to the coast.
hedonic - ACS median home price data used for hedonic models.
jawbone	- Jawbone sleep tracking data.			
qcew - Quarterly Census of Employment and Wages
qol - Quality Of Life data from Albouy.
weather - NOAA weather data


*******************
* Scripts
*******************
* These scripts were executed under Stata versions 13 and 14, on MacOS (OS X)
* In most of these scripts, set the work local to the directory in which you are working by replacing "/DIRECTORY".
* Scripts should be executed in the listed order, except where noted.

* Preliminary data processing
Centroids_proc.do - Prepares files that map CBSA and NECTA codes to latitude and longitude of centroids.
Coastal_proc.do - Reads coastal distances (computed in ArcGIS) and saves them in Stata format. GIS shapefiles and unprocessed output are located in "/data/gis".
demographic_proc.do - Processes county-level demographic variables from Census and USDA
BEA_proc.do - Processes state- and county-level variables from BEA.
weather_data.m - Processes NOAA weather data.
atus_weather_clean.do - Cleaning of weather variables from "weather_data.m" for use with ATUS.

* ATUS/CPS
atus_program_flow.do - Calls three programs (download_atus_zip_files.do, atus_create_stata_files.do, and atus_combine.do) that download the raw ATUS files from the BLS, create Stata-format ATUS data files, and prepares the files for processing.
CPS_proc.do - ATUS covers a subsample of CPS respondents, and CPS files contain some variables not present in ATUS. This script processes geographic identifiers from basic CPS files for so they can be merged onto ATUS.
CPS_merge.do - Merges geographic variables from CPS onto ATUS.
atus_proc.do - Processes the combined CPS-ATUS files and adds additional variables for estimation. This is the most important data processing script for ATUS.
ATUS_activity_file_process.do - Combines variables from ATUS activity file with the primary data set output from "atus_proc.do".
ATUS_models_season.do - Models of short-run effects.
Dataproc_QOL.do - Creates file with Albouy QOL measures.
Dataproc_twosample.do - Collapses ATUS to a cross-section in locations for long-run analysis.
ATUS_models_xsec.do - Models of long-run effects.
seasonal_patterns.R - Simulates seasonal confounding in short-run models.

* QCEW
QCEW_proc_quarterly.do - Processes raw QCEW files from BLS.
Quarterly_county_sunsets.do - Compute sunset times for QCEW data.
Proc_Census_countyDB.do - Processes Census Counties Database.
CountiesDB_proc.do - Subsets Census county database for merge to QCEW data.
QCEW_sunset_merge.do - Merging sunset times and covariates onto QCEW.
QCEW_collapse.do - Collapses from county-quarter level to a cross section in counties.
QCEW_models_xsec.do - Estimates reduced-form models.
robustness_models.do - Robustness checks.

* Hedonic analysis
Hedonic_proc.do - Processes Census ACS median home price data.
Hedonic_models.do - Estimates hedonic regressions on sunset time.

* Jawbone
Jawbone_proc.R - (R script.) Processes text file downloaded from Jawbone website.
Jawbone.do - Estimates relationships between sleep variables and sunset time.

* Historical sorting
historic_sorting.do - Analyzes population responses to historical changes in time zone schemes. (This material appears in the appendix.)

* Other files
scheme-jleanc.scheme - Graphical scheme for Stata.
solar_calculator.ado - Calculates sunset time based on location and time variables. Called by other files; there is no need to execute this file independently. For convenience it can be placed in one's personal Stata /ado folder.
atus_maps.do - Produces map of counties in which we observe ATUS respondents' locations at the county (as opposed to CBSA or state) level.
annual_atus_sunset.do - Takes geocoded ATUS data and computes sunset times. This script is called by "atus_proc.do"; it does not need to be executed independently.



